package com.dc.chat.app.biz.impl;

import com.dc.chat.app.biz.FriendMessageBiz;
import com.dc.chat.app.service.mp.FriendMessageService;
import com.dc.chat.app.service.mp.FriendService;
import com.dc.chat.app.service.mp.UserService;
import com.dc.chat.entity.dao.FriendMessage;
import com.dc.chat.entity.dao.User;
import com.dc.chat.entity.to.ResponseBean;
import com.dc.chat.interceptor.security.SecurityInterceptor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
@Service
public class FriendMessageBizImpl implements FriendMessageBiz {
    @Resource
    FriendMessageService friendMessageService;
    @Resource
    UserService userService;
    @Resource
    FriendService friendService;
    @Override
    public ResponseBean<Map<String, List<FriendMessage>>> getFriendMessage() {
        Map<String,List<FriendMessage>> map=new HashMap<>();
        String username = SecurityInterceptor.threadLocal.get();
        User user = userService.selectByUserName(username);
        Collection<Integer> friendsIds = friendService.getFriendsId(user.getId());
        for (Integer friendId : friendsIds) {
            List<FriendMessage> friendMessage = friendMessageService.getFriendMessage(friendId, user.getId());
            String key=user.getId()+"#"+friendId;
            map.put(key,friendMessage);
        }
        return ResponseBean.success("查询成功",map);
    }
}
